import {request} from '../../network/index'
const app = getApp()
Page({

	/**
	 * 页面的初始数据 
	 */
	data: {
		active:1018,
		searchData:"",
		keywords:'',
		time:[]
	},
	async onChange(event) {
		let type = event.detail.name
		let searchResult = await request('/search',{keywords:this.data.keywords,limit:10,type})
		if(event.detail.name == 10){
			searchResult.data.result.albums = searchResult.data.result.albums.filter(item=>item.publishTime = app.time(item.publishTime))
		}
		console.log(searchResult);
		wx.setStorageSync('searchResult',searchResult.data.result)
		this.setData({
			searchData:searchResult.data.result
		})
  },
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		const eventChannel = this.getOpenerEventChannel()
		eventChannel.on('search',async keywords => {
			let searchResult = await request('/search',{keywords,limit:10,type:"1018"})
			console.log(searchResult);
			searchResult.data.result.album.albums = searchResult.data.result.album.albums.filter(item=>item.publishTime = app.time(item.publishTime))

			this.setData({
				searchData:searchResult.data.result,
				keywords
			})
		})
	},
	toSearch(){
		wx.navigateBack()
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {
	
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {
		
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})